<?php
// classe de base, avec ses membres et ses méthodes
//test test 3
class Gallery extends Controller{

  var $_defaultPage="index";
  var $_cssfile = "style.css";

   function Wiki() {
      parent::Controller();
      $this->load->model('wiki_model');
   }

    function Gallery()
    {
    	 redirect("wiki/read/");
    }

   /**
    * Retrieves the requested page and outputs it
    * @param  string  $pagename  page to display
    * @param  string  $message   message to display (error, confirmation...)
    */
    function read($pagename="")
    {
        $basepagename=$this->wiki_model->basePagename($pagename);
        if ($pagename!=$basepagename)
            redirect ("/wiki/read/".$basepagename);
        if (!$this->wiki_model->pageExists($pagename)) 
            redirect ("/wiki/read/".$this->_defaultPage);
        //is authorized??
        if (!$this->user->isAuthorized())
            redirect ("/wiki/read/".$this->_defaultPage);

        $output['pagename']=$pagename;
        $this->load->helper('wiki');
        //choose template & css file
        $style=$this->wiki_model->getStyle($pagename);
        $tpl_file='wiki/'.$style['tpl'];
        $output['cssFile']=$style['css'];
        //test
        $output['cssFile']=$style['css'];
        //test
        $this->load->view($tpl_file,$output);
    }
    
   /**
    * Returns the rendered page without any template context
    *
    */              
    function readpart($pagename="")
    {
        $basepagename=$this->wiki_model->basePagename($pagename);
        if ($pagename!=$basepagename) 
            redirect ("/wiki/read/".$basepagename);
        //is authorized??
        if (!$this->user->isAuthorized())
            redirect ("/wiki/read/".$basepagename);
                   
        if (!$this->wiki_model->pageExists($pagename))
            $pagename = $this->_defaultPage;
        $content=$this->wiki_model->wiki2html($pagename);
        echo $content['main'];
    }
  
} 
?>
